import { Component, OnInit } from '@angular/core';
import {User} from "../model/user";
import {Router} from "@angular/router";

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css']
})
export class HeaderComponent implements OnInit {
  public currentUser: User;
  public userName: string;
  public currentId: number;
  public menus: Array<Menu>;

  constructor(public  routInfo: Router) {
  }
  ngOnInit() {
    this.currentUser = JSON.parse(sessionStorage.getItem("currentUser"));
    this.userName = this.currentUser.userName;
    this.menus=[
      new Menu(1,'首页','/rector','simple',[]),
      new Menu(2,'考试学情追踪','','dropdown',[
        new Menu(21,'最新考试学情','','',[]),
        new Menu(22,'全部考试列表','./examList','',[])
      ]),
      new Menu(3,'设置','/rector','simple',[])
    ]
  }
  nav(menu: Menu) {
    //console.log([menu.url]);
    if(menu.type!='dropdown'){
      this.routInfo.navigate([menu.url]);
    }
    this.currentId=menu.id;
  }
}
export class Menu{
  constructor(
    public id: number,
    public name: string,
    public url: string,
    public type: string,
    public child: Array<Menu>){}
}
